from flask import (Flask, render_template, request, jsonify, flash,
                   redirect, url_for, session, send_from_directory)
import sys
import datetime
app = Flask(__name__)
app.secret_key = "dfaskljdkf4378943%&*%7"



@app.route('/')
def start_web():
    # if session.get('admin', None) is None:
    #     return redirect(url_for("login"))
    # json_path = config.path + "index_data.json"
    # profit = {}
    # if os.path.exists(json_path):
    #     with open(json_path) as fp:
    #         profit = json.load(fp)
    profit = 13
    print("index4")
    return render_template('index.html', profit=profit)



def start_app():
    app.run(threaded=True, host='0.0.0.0', port=8006)


@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('pwd')
        if username != "zhanghang" and password != "123":
            flash("用户名或密码错误")
        else:
            session['admin'] = "zhanghang"
            return redirect(url_for("start_web"))
    return render_template('login.html')


@app.route('/loginOut')
def login_out():
    session.pop('admin')
    return redirect(url_for('login'))


@app.route('/noPermission')
def no_permission():
    return render_template('noPermission.html')


@app.route('/taskSchedule')
def task1():
    return render_template('taskSchedule.html')

@app.route('/task2')
def task2():
    return render_template('task2.html')

@app.route('/task3')
def task3():
    return render_template('task3.html')

@app.route('/task4')
def task4():
    return render_template('task4.html')

@app.route('/task5')
def task5():
    return render_template('task5.html')

@app.route('/task6')
def task6():
    return render_template('task6.html')


@app.route('/permissionManage')
def permission_manage():
    if session.get('admin', None) is None:
        return redirect(url_for("login"))
    return render_template('permissionManage.html', version=str(datetime.datetime.today()))


if __name__ == '__main__':


    start_app()